package me.jiatao.wan.ui.main.wechat

import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.hi.dhl.binding.viewbind
import kotlinx.coroutines.delay
import me.jiatao.wan.R
import me.jiatao.wan.common.ui.LoadingLottieAnimation
import me.jiatao.wan.databinding.FragmentWechatBinding

class WechatFragment : Fragment(R.layout.fragment_wechat) {

    private val mBinding by viewbind<FragmentWechatBinding>()

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        mBinding.retryButton.setOnClickListener {
            loadTest()
        }

        loadTest()
    }

    private fun loadTest() {
        lifecycleScope.launchWhenCreated {
            mBinding.apply {

                retryButton.isVisible = false
                lottieAnimation.status = LoadingLottieAnimation.State.LOADING
                delay(3000)

                retryButton.isVisible = true
                lottieAnimation.status = LoadingLottieAnimation.State.ERROR
            }
        }
    }
}